import requests
import json

# 配置 API 信息
# api_url = "http://localhost:3001/api/v1/workspace/echarts-63767994/chat"
api_url = "http://localhost:3001/api/v1/workspace/echarts-63767994/stream-chat"  # 流式聊天
# api_url = "http://localhost:3001/api/v1/workspace/echarts/chat"
# api_url = "http://localhost:3001/api/v1/workspace/35eae595-109a-4682-a3a1-777721e92544/chat"
api_key = "7RGJTM8-WVP40QW-NC6TC8T-KXG4929"

# 要发送的消息内容
message = {
    "message": "帮我写一个鞋子的带货脚本",
    "context": []  # 可以在这里传入对话上下文，作为多轮对话的基础
}

# 设置请求头
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_key}"  # 如果接口需要 Bearer Token 认证
}

try:
    # 发送 POST 请求
    response = requests.post(api_url, headers=headers, data=json.dumps(message))

    # 检查响应状态码
    response.raise_for_status()  # 这将对 4XX 或 5XX 响应抛出 HTTPError

    result = response.json()
    # print("完整回复内容：", result)
    print("回复内容：", result.get('textResponse', '未找到回复内容'))

except requests.exceptions.HTTPError as http_err:
    print(f"HTTP 错误发生: {http_err}")
    print("响应内容：", response.text if 'response' in locals() else '无响应')
except Exception as err:
    print(f"其他错误发生: {err}")
